{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<a href=\"https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv\" target=\"_blank\"><img align=\"left\" src=\"data/cover.jpg\" style=\"width: 76px; height: 100px; background: white; padding: 1px; border: 1px solid black; margin-right:10px;\"></a>\n",
    "*This notebook contains an excerpt from the book [Machine Learning for OpenCV](https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv) by Michael Beyeler.\n",
    "The code is released under the [MIT license](https://opensource.org/licenses/MIT),\n",
    "and is available on [GitHub](https://github.com/mbeyeler/opencv-machine-learning).*\n",
    "\n",
    "*Note that this excerpt contains only the raw code - the book is rich with additional explanations and illustrations.\n",
    "If you find this content useful, please consider supporting the work by\n",
    "[buying the book](https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv)!*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Measuring-Model-Performance-with-Scoring-Functions](03.01-Measuring-Model-Performance-with-Scoring-Functions.ipynb) | [Contents](../README.md) | [Using Regression Models to Predict Continuous Outcomes](03.03-Using-Regression-Models-to-Predict-Continuous-Outcomes.ipynb) >"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Understanding the k-NN Classifier\n",
    "\n",
    "The $k$-NN algorithm is arguably one of the simplest machine learning algorithms. The\n",
    "reason for this is that we basically only need to store the training dataset. Then, in order to\n",
    "make a prediction for a new data point, we only need to find the closest data point in the\n",
    "training dataset-its **nearest neighbor**.\n",
    "\n",
    "In a nutshell, the $k$-NN algorithm argues that a data point probably belongs to the same\n",
    "class as its neighbors.\n",
    "Of course, some neighborhoods might be a little more complicated. In this case, we would\n",
    "not just consider our closest neighbor (where $k=1$), but instead our $k$ nearest neighbors.\n",
    "\n",
    "That's all there is to it."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Implementing k-NN in OpenCV\n",
    "\n",
    "Using OpenCV, we can easily create a $k$-NN model via the function `cv2.ml.KNearest_create`. Building the model then involves the following steps:\n",
    "- Generate some training data.\n",
    "- Create a k-NN object for a given number k.\n",
    "- Find the k nearest neighbors of a new data point that we want to classify.\n",
    "- Assign the class label of the new data point by majority vote.\n",
    "- Plot the result.\n",
    "\n",
    "We first import all the necessary modules: OpenCV for the $k$-NN algorithm, NumPy for\n",
    "data munging, and Matplotlib for plotting. If you are working in a Jupyter Notebook, don't\n",
    "forget to call the `%matplotlib inline` magic:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import cv2\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "plt.style.use('ggplot')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Generating the training data\n",
    "\n",
    "The first step is to generate some training data. For this, we will use NumPy's random\n",
    "number generator. As discussed in the previous section, we will fix the seed of the random\n",
    "number generator, so that re-running the script will always generate the same values:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "np.random.seed(42)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can pick a single data point with `0 <= x <= 100` and `0 <= y <= 100`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([51, 92])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_data_point = np.random.randint(0, 100, 2)\n",
    "single_data_point"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As shown in the preceding output, this will pick two random integers between 0 and 100.\n",
    "We will interpret the first integer as the data point's $x$ coordinate on the map, and the\n",
    "second integer as the point's $y$ coordinate. Similarly, let's pick a label for the data point:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_label = np.random.randint(0, 2)\n",
    "single_label"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Turns out that this data point would have class 0.\n",
    "\n",
    "Let's wrap this process in a function that takes as input the number of data points to\n",
    "generate (that is, `num_samples`) and the number of features every data point has (that is,\n",
    "`num_features`):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def generate_data(num_samples, num_features=2):\n",
    "    \"\"\"Randomly generates a number of data points\"\"\"\n",
    "    data_size = (num_samples, num_features)\n",
    "    train_data = np.random.randint(0, 100, size=data_size)\n",
    "    labels_size = (num_samples, 1)\n",
    "    labels = np.random.randint(0, 2, size=labels_size)\n",
    "    \n",
    "    return train_data.astype(np.float32), labels"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's put the function to test and generate an arbitrary number of data points, let's say\n",
    "eleven, whose coordinates are chosen randomly:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 71.,  60.],\n",
       "       [ 20.,  82.],\n",
       "       [ 86.,  74.],\n",
       "       [ 74.,  87.],\n",
       "       [ 99.,  23.],\n",
       "       [  2.,  21.],\n",
       "       [ 52.,   1.],\n",
       "       [ 87.,  29.],\n",
       "       [ 37.,   1.],\n",
       "       [ 63.,  59.],\n",
       "       [ 20.,  32.]], dtype=float32)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data, labels = generate_data(11)\n",
    "train_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we can see from the preceding output, the `train_data` variable is an 11 x 2 array, where\n",
    "each row corresponds to a single data point. We can also inspect the first data point with its\n",
    "corresponding label by indexing into the array:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([ 71.,  60.], dtype=float32), array([1]))"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data[0], labels[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This tells us that the first data point is a blue square (because it has class 0) and lives at\n",
    "location $(x, y) = (71, 60)$ on the town map. If we want, we can plot this data point on\n",
    "the town map using Matplotlib:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.text.Text at 0x7fc9ad22f6a0>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAENCAYAAADgwHn9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X1UVHXiBvBnmAEnMF5mBmFnyYjA1N01Wt/I15XF3WNW\n23Y6ZW2tgKYypGVa1GqL5wjukHbYfIuyQNPWVneV7NV25CgmyAq+UbKmLZgxFi9DYMCAM9zfH/38\nLiDUlZh7GXs+f83cuXe+DxyPD/f1q5EkSQIREREAH7UDEBHRwMFSICIigaVAREQCS4GIiASWAhER\nCSwFIiISWApERCSwFIiISGApEBGRwFIgIiJBp3aAvrDb7WpH6JHJZEJdXZ3aMWTxlqzekhNgVk9h\n1v5hNptlrcc9BSIiElgKREQksBSIiEhgKRARkcBSICIiQbGrj5qbm5GTk4Pz589Do9EgJSUFR48e\nRWlpKTQaDYK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SICIigaVAREQC\nS4GIiASWAhERCSwFIiISWApERCT8H9ALRZMZBvP8AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc9ad207198>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(train_data[0, 0], train_data[0, 1], 'sb')\n",
    "plt.xlabel('x coordinate')\n",
    "plt.ylabel('y coordinate')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But what if we want to visualize the whole training set at once? Let's write a function for\n",
    "that. The function should take as input a list of all the data points that are blue squares\n",
    "(`all_blue`) and a list of the data points that are red triangles (`all_red`):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def plot_data(all_blue, all_red):\n",
    "    plt.figure(figsize=(10, 6))\n",
    "    plt.scatter(all_blue[:, 0], all_blue[:, 1], c='b', marker='s', s=180)\n",
    "    plt.scatter(all_red[:, 0], all_red[:, 1], c='r', marker='^', s=180)\n",
    "    plt.xlabel('x coordinate (feature 1)')\n",
    "    plt.ylabel('y coordinate (feature 2)')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try it on our dataset! First we have to split all the data points into red and blue sets. We\n",
    "can quickly select all the elements of the `labels` array created earlier that are equal to 0,\n",
    "using the following command (where `ravel` flattens the array):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False, False,  True, False,  True,  True,  True,  True,\n",
       "        True, False], dtype=bool)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels.ravel() == 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All the blue data points are then all the rows of the `train_data` array created earlier,\n",
    "whose corresponding label is 0:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "blue = train_data[labels.ravel() == 0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The same can be done for all the red data points:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "red = train_data[labels.ravel() == 1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, let's plot all the data points:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmQAAAF6CAYAAAC3JUTKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8U3W+//F3mrSUgnRJWCwgUAqyuLBTYQYE6swVXBgf\nLhcFqeBGuYDKoAwj4jysIwhYRIrVYSkuA8o8xl7Xq4M8QGWzQst4AbFlUTbtklIotJQ2+f3hr7lU\n2nJaSE5IXs+/mpyc5N1+H9E3n3NyYnG73W4BAADANCFmBwAAAAh2FDIAAACTUcgAAABMRiEDAAAw\nGYUMAADAZBQyAAAAk1HIAAAATEYhAwAAMBmFDAAAwGQUMgAAAJNRyAAAAExmMztAYxw9erRR+zkc\nDhUWFl7iNLgUWBv/xvr4L9bGf7E2/s1X6xMbG2vocUzIAAAATEYhAwAAMBmFDAAAwGQUMgAAAJNR\nyAAAAExGIQMAADDZZXnZCwAAqs2YEan9+xv+v7O4uErNn1/ihURAw1HIAACXtf37bdq6tYnZMYCL\nwiFLAAAAk1HIAAAATEYhAwAAMBmFDAAAwGQUMgAAAJNRyAAAAExGIQMAADAZhQwAAMBkFDIAAACT\nUcgAAABMRiEDAAAwGYUMAADAZHy5OADgshYXV+nT/QBvoJABAC5r8+eXmB0BuGgcsgQAADAZhQx+\nwfLll2ZHAADANBQymM6amyvb3XfLmpdndhQAAExBIYPpIlNSZHE6FZmSYn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V+u677yRJgwcP1kcffaT8/HyVl5dr9erVuuGGG2S1\nWjVo0CBlZ2fr22+/VWVlpT744AOFhobq6quvrvV1unbtqpCQEH3yySeqqqrStm3blJeX16jfrby8\nXGFhYYqIiFBpaanWrl1bY3tkZKR+/vlnz+2+ffvq2LFj+uKLL1RZWanKykrl5eXp8OHDtT5/7969\n6z3EGB8fr6ZNmyozM1MVFRVyuVz68ccfPb9PWVmZIiIiFB4eriNHjuizzz6rN1+HDh106NAhHTx4\nUBUVFXr33Xfr/f1DQkI0YsQIZWRkqKSkRJLkdDrrvZZYRUWFzp49K+mXy3qcWwClX64D17t373pf\nF8ClQSEDgkRWVpZycnL08MMPS5LGjx+vAwcO6MsvvzzvsSEhIXrqqaf0008/KTk5WZMmTfKcCzVs\n2DANGTJEc+bM0eTJkxUaGqoJEyZIkmJjYzVlyhStWLFCEydO1Pbt2/XUU0/JZqt9GG+z2fTHP/5R\nGzZs0AMPPKDNmzdrwIABjfr9Ro4cqYqKCk2cOFF//vOf1atXr/O2b9u2TQ888IBWrFihpk2b6umn\nn9amTZv0yCOP6OGHH9bbb79d4wMI5+rbt6+OHDlS4/BrbX+zgwcPavLkyZo4caJee+01nT59WpI0\nbtw4ffXVV7r//vv12muvnXfi/l133aW0tDQlJSVp8+bNio2N1Z133qnnnntO06ZN85zDV5/77rtP\nbdq00Z///GeNHz9ezz33nI4ePVrn48eOHav7779fkvTYY49p7Nixnm15eXlq0qSJ4uPjL/i6AC6e\nxV09zwcA1GvdunU6fPhwjfPEAtWCBQs0fPhw9enTx+woQFCgkAEAAJiMQ5YAAAAmo5ABAACYjEIG\nAABgMgoZAACAyShkAAAAJqOQAQAAmIxCBgAAYDIKGQAAgMn+H7DBLn6fH83bAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc9ab1a4828>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_data(blue, red)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Training the classifier\n",
    "\n",
    "Now it's time to train the classifier.\n",
    "\n",
    "As all other machine learning functions, the $k$-NN classifier is part of OpenCV 3.1's `ml` module. You can create a new classifier using the following command:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "knn = cv2.ml.KNearest_create()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then pass our training data to the train method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn.train(train_data, cv2.ml.ROW_SAMPLE, labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, we have to tell knn that our data is an $N \\times 2$ array (that is, every row is a data point).\n",
    "Upon success, the function returns True."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Predicting the label of a new data point\n",
    "\n",
    "The other really helpful method that `knn` provides is called `findNearest`. It can be used to\n",
    "predict the label of a new data point based on its nearest neighbors.\n",
    "\n",
    "Thanks to our `generate_data` function, it is actually really easy to generate a new data\n",
    "point! We can think of a new data point as a dataset of size 1:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 91.,  59.]], dtype=float32)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "newcomer, _ = generate_data(1)\n",
    "newcomer"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Our function also returns a random label, but we are not interested in that. Instead, we\n",
    "want to predict it using our trained classifier! We can tell Python to ignore an output value\n",
    "with an underscore (`_`).\n",
    "\n",
    "Let's have a look at our town map again. We will plot the training set as we did earlier, but\n",
    "also add the new data point as a green circle (since we don't know yet whether it is\n",
    "supposed to be a blue square or a red triangle):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmQAAAF6CAYAAAC3JUTKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl4U3WixvE3TbpQkC4JiwUESkHAjVUqjoBQZ67gwvi4\nXBSkghvl4sagDKPiPNYRRCwiRXRYisuAMs/IuF4d5AEUrFbaMl5EbFkUKNolbaHQhTa5f3ibS6Ut\np4XkhOT7+avJOSd5k99z9OV3Ts6xuN1utwAAAGCaELMDAAAABDsKGQAAgMkoZAAAACajkAEAAJiM\nQgYAAGAyChkAAIDJKGQAAAAmo5ABAACYjEIGAABgMgoZAACAyShkAAAAJrOZHaA1CgoKWrWdw+FQ\ncXHxWU6Ds4Gx8W+Mj/9ibPwXY+PffDU+cXFxhtZjhgwAAMBkFDIAAACTUcgAAABMRiEDAAAwGYUM\nAADAZBQyAAAAk52Tl70AAKDerFlR2ru35f87i4+v1YIF5V5IBLQchQwAcE7bu9emzMxws2MAZ4RD\nlgAAACajkAEAAJiMQgYAAGAyChkAAIDJKGQAAAAmo5ABAACYjEIGAABgMgoZAACAyShkAAAAJqOQ\nAQAAmIxCBgAAYDIKGQAAgMm4uTgA4JwWH1/r0+0Ab6CQAQDOaQsWlJsdAThjHLIEAAAwGYUMfsHy\n2WdmRwAAwDQUMpjOmpcn2623ypqfb3YUAABMQSGD6aJSU2VxOhWVmmp2FAAATEEhg6mseXkKzc2V\nJIXm5jJLBgAIShQymCoqNVXW4mJJkrWoiFkyAEBQopDBNCfPjtVjlgwAEIwoZDDNybNj9ZglAwAE\nIwoZTNHY7Fg9ZskAAMGGQgZTNDY7Vo9ZMgBAsKGQweeamx2rxywZACCY+Oxelu+//742btwoi8Wi\nbt26KSUlRWVlZVq0aJEqKirUs2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O1J133ilJeuihhzRx4kTPsvz8fIWHhyshIeG07wvgzFnc9fP5AIBmbdiwQQcPHmxw\nnligev755zV69GgNGjTI7ChAUKCQAQAAmIxDlgAAACajkAEAAJiMQgYAAGAyChkAAIDJKGQAAAAm\no5ABAACYjEIGAABgMgoZAACAyf4XMbjFi/uUq2cAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc9ab181518>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_data(blue, red)\n",
    "plt.plot(newcomer[0, 0], newcomer[0, 1], 'go', markersize=14);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you had to guess based on its neighbors, what label would you assign the new data pointblue\n",
    "or red?\n",
    "\n",
    "Well, it depends, doesn't it? If we look at the house closest to it (the one living roughly at $(x,\n",
    "y) = (85, 75)$), we would probably assign\n",
    "the new data point to be a red triangle as well. This is exactly what our classifier would\n",
    "predict for $k=1$:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predicted label:\t [[ 1.]]\n",
      "Neighbor's label:\t [[ 1.]]\n",
      "Distance to neighbor:\t [[ 250.]]\n"
     ]
    }
   ],
   "source": [
    "ret, results, neighbor, dist = knn.findNearest(newcomer, 1)\n",
    "print(\"Predicted label:\\t\", results)\n",
    "print(\"Neighbor's label:\\t\", neighbor)\n",
    "print(\"Distance to neighbor:\\t\", dist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, knn reports that the nearest neighbor is 250 arbitrary units away, that the neighbor\n",
    "has label 1 (which we said corresponds to red triangles), and that therefore the new data\n",
    "point should also have label 1. The same would be true if we looked at the $k=2$ nearest\n",
    "neighbors, and the $k=3$ nearest neighbors.\n",
    "\n",
    "But we want to be careful not to pick arbitrary\n",
    "even numbers for $k$. Why is that? Refer to page 64 for the answer."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, what would happen if we dramatically widened our search window and classified\n",
    "the new data point based on its $k=7$ nearest neighbors (circled with a solid line in the figure\n",
    "mentioned earlier)?\n",
    "\n",
    "Let's find out by calling the `findNearest` method with $k=7$ neighbors:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predicted label:\t [[ 0.]]\n",
      "Neighbor's label:\t [[ 1.  1.  0.  0.  0.  1.  0.]]\n",
      "Distance to neighbor:\t [[  250.   401.   784.   916.  1073.  1360.  4885.]]\n"
     ]
    }
   ],
   "source": [
    "ret, results, neighbor, dist = knn.findNearest(newcomer, 7)\n",
    "print(\"Predicted label:\\t\", results)\n",
    "print(\"Neighbor's label:\\t\", neighbor)\n",
    "print(\"Distance to neighbor:\\t\", dist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Suddenly, the predicted label is 0 (blue square). The reason is that we now have four\n",
    "neighbors within the solid circle that are blue squares (label 0), and only three that are red\n",
    "triangles (label 1). So the majority vote would suggest making the newcomer a blue square\n",
    "as well.\n",
    "\n",
    "For $k=6$, there is a tie:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predicted label:\t [[ 0.]]\n",
      "Neighbors' labels:\t [[ 1.  1.  0.  0.  0.  1.]]\n",
      "Distance to neighbors:\t [[  250.   401.   784.   916.  1073.  1360.]]\n"
     ]
    }
   ],
   "source": [
    "ret, results, neighbors, dist = knn.findNearest(newcomer, 6)\n",
    "print(\"Predicted label:\\t\", results)\n",
    "print(\"Neighbors' labels:\\t\", neighbors)\n",
    "print(\"Distance to neighbors:\\t\", dist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Alternatively, predictions can be made with the `predict` method. But first, need to set `k`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, array([[ 0.]], dtype=float32))"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn.setDefaultK(7)\n",
    "knn.predict(newcomer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, array([[ 0.]], dtype=float32))"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn.setDefaultK(6)\n",
    "knn.predict(newcomer)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see, the outcome of $k$-NN changes with the number $k$. However, often we do not\n",
    "know beforehand which number $k$ is the most suitable. A naive solution to this problem is\n",
    "just to try a bunch of values for $k$, and see which one performs best. We will learn more\n",
    "sophisticated solutions in later chapters of this book."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Measuring-Model-Performance-with-Scoring-Functions](03.01-Measuring-Model-Performance-with-Scoring-Functions.ipynb) | [Contents](../README.md) | [Using Regression Models to Predict Continuous Outcomes](03.03-Using-Regression-Models-to-Predict-Continuous-Outcomes.ipynb) >"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
